package com.kanche.bigbaby.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.kanche.bigbaby.support.base.BasePage;

import java.util.List;

/**
 * Created by Chenshao_Young on 15/5/18.
 */
public class BasePageVPAdapter extends PagerAdapter {


    List<BasePage> basePageList;

    String[] titles ;

    public BasePageVPAdapter(List<BasePage> basePageList,String[] titles ) {
        this.basePageList = basePageList;
        this.titles = titles;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(basePageList.get(position).getContentView());
        return basePageList.get(position).getContentView();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(basePageList.get(position).getContentView());
//        super.destroyItem(container, position, object);
    }

    @Override
    public int getCount() {
        return basePageList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}
